<!--- Keep it lean and clean --->
<CFSETTING ENABLECFOUTPUTONLY="yes">
<!---
	Name         : Wap
	Author       : Ben Forta 
	Created      : 
	Last Updated : August 6, 2003
	History      : Reset history for version 3.0
	Purpose		 : Blog WAP feed.
--->


<!--- Max title length --->
<CFSET maxTitleLength = 100>
<!--- Max number of chars to include in brief view --->
<CFSET maxBriefEntryLength = 250>
<!--- Max number of chars to include in detail view --->
<CFSET maxDetailEntryLength = 1250>
<!--- Max number of cards to include in brief view deck --->
<CFSET maxBriefEntries = 5>

<!--- Any needed UDF's --->
<!--- Prep WAP entry (restrict size, escape any $ --->
<CFFUNCTION NAME="PrepWAPEntry" RETURNTYPE="string" OUTPUT="false">
	<CFARGUMENT NAME="text" TYPE="string" REQUIRED="true">
	<CFARGUMENT NAME="length" TYPE="numeric" REQUIRED="true">

	<CFSET var result="">
	
	<!--- Get first n chars --->
	<CFSET result=Left(Trim(text), length)>
	<!--- Append a ... if needed --->
	<CFIF Len(Trim(text)) GT Len(result)>
		<CFSET result = result & "...">
	</CFIF>
	<!--- Make safe --->
	<CFSET result=Replace(result, "$", "$$", "ALL")>
	
	<CFRETURN HTMLEditFormat(result)>
	
</CFFUNCTION>

<!--- If search specified, set mode to "s" --->
<CFIF IsDefined("search") AND Len(Trim(search))>
	<CFSET mode="s">
<!--- If entry specified, set mode to "e" --->
<CFELSEIF IsDefined("entry")>
	<CFSET mode="e">
</CFIF>

<!--- Set default mode (top card) --->
<CFPARAM NAME="mode" DEFAULT="t"> <!--- Default to top --->

<!--- If browse mode or search, default to page 1 --->
<CFIF mode IS "b" OR mode IS "s">
	<CFPARAM NAME="page" DEFAULT="1">
	<CFSET startCard=((page-1)*maxBriefEntries)+1>
	<CFSET totalEntries=page*maxBriefEntries>
	<CFSET nextPage=page+1>
<CFELSE>
	<CFSET startCard=1>
</CFIF>

<!--- Define params structure --->
<CFSET params=StructNew()>

<CFIF mode IS "b"> <!--- Browse --->
	<CFSET params.maxEntries = totalEntries> <!--- Not too many for WAP --->
<CFELSEIF mode IS "s"> <!--- Search --->
<CFELSEIF mode IS "e"> <!--- Entry --->
	<CFSET params.byentry = Val(entry)>
<CFELSE>
	<!--- If top page, just get newest blog entry --->
	<CFSET params.maxEntries = 1>
</CFIF>

<!--- WAP title --->
<CFSET pageTitle=APPLICATION.blog.GetProperty("blogTitle")>

<!--- Get entries --->
<CFIF mode IS "s">
	<CFSET articles = APPLICATION.blog.Search(Trim(search))>
<CFELSE>
	<CFSET articles = APPLICATION.blog.GetEntries(params)>
</CFIF>

<!--- Set to wap --->
<CFOUTPUT>
<CFCONTENT Type="text/vnd.wap.wml">
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">

<wml>
</CFOUTPUT>

<!--- Top level card (for all but mode=e) --->
<CFIF NOT mode IS "e">
	<CFOUTPUT>
	<card id="main" title="#pageTitle#">
	<do type="accept">
	   <go href="##e$eid" />
	</do>
	<CFIF mode IS "s">
		<!--- If search mode, display search string --->
		<p align="center"><b>Search: #search#</b></p>
	</CFIF>
	<p>
	</CFOUTPUT>
	<CFOUTPUT QUERY="articles" STARTROW="#startCard#" MAXROWS="#maxBriefEntries#"> 
	<CFIF articles.RecordCount GT 1>#CurrentRow#: </CFIF><anchor><go href="##e#id#"/>#PrepWAPEntry(title, maxTitleLength)#</anchor><br/>
	</CFOUTPUT>
	<CFOUTPUT>
	<br/>
	<CFIF mode IS "b">
		[<a href="#CGI.SCRIPT_NAME#?mode=b&amp;page=#nextPage#">More ...</a>]<br/>
		[<a href="#CGI.SCRIPT_NAME#?mode=t">Main</a>]
	<CFELSEIF mode IS "s">
		[<anchor>
		More ...
			<go href="#CGI.SCRIPT_NAME#">
				<postfield name="search" value="$search" />
				<postfield name="page" value="#nextPage#" />
			</go>
		</anchor>]<br/>
		[<a href="#CGI.SCRIPT_NAME#?mode=t">Main</a>]
		[<a href="#CGI.SCRIPT_NAME#?mode=b">Browse</a>]
	<CFELSE>
		[<a href="#CGI.SCRIPT_NAME#?mode=b">Browse</a>]
	</CFIF>
	[<a href="##search">Search</a>]
	</p>
	</card>
	</CFOUTPUT>
</CFIF>
<!--- Create a drill-down card for each entry --->
<CFIF mode IS "e">
	<CFSET bodyLength=maxDetailEntryLength>
<CFELSE>
	<CFSET bodyLength=maxBriefEntryLength>
</CFIF>
<CFOUTPUT QUERY="articles" STARTROW="#startCard#" MAXROWS="#maxBriefEntries#">
<card id="e#id#" title="#pageTitle#">
<p align="center">
<b>#PrepWAPEntry(title, maxTitleLength)#</b>
</p>
<p>
#PrepWAPEntry(body, bodyLength)#
<br/>
<CFIF NOT mode IS "e">[<a href="#CGI.SCRIPT_NAME#?entry=#id#">More ...</a>]<br/></CFIF>
<br/>
<i>Posted: #DateFormat(posted)#</i>
<br/><br/>
[<a href="#CGI.SCRIPT_NAME#?mode=t">Main</a>]
[<a href="#CGI.SCRIPT_NAME#?mode=b">Browse</a>]
[<a href="##search">Search</a>]
</p>
</card>
</CFOUTPUT>
<CFOUTPUT>
<card id="search" title="#pageTitle#">
<do type="accept" label="Search">
	<go href="#CGI.SCRIPT_NAME#?search=$search"/>
</do>
<p align="center">
<b>Search</b><br/>
</p>
<p>
<fieldset title="Search">
Text: <input name="search" size="15" emptyok="true"/>
<anchor>
	Do Search
	<go href="#CGI.SCRIPT_NAME#">
		<postfield name="search" value="$search" />
	</go>
</anchor>
<br/><br/>
</fieldset>
[<a href="#CGI.SCRIPT_NAME#?mode=t">Main</a>]
[<a href="#CGI.SCRIPT_NAME#?mode=b">Browse</a>]
</p>
</card>

</wml>
</CFOUTPUT>
